surface: Add coordinate translation
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 May 2019 03:41:56 +0000 (23:41 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 29 May 2019 18:04:08 +0000 (18:04 +0000)
We maintain offsets for popups, so we can translate
coordinates between surfaces that are attached directly
or indirectly to the same toplevel. Add an api for that.

gdk/gdksurface.c
gdk/gdksurface.h

index b3f0c64223b3244e88a57edb79c3fd8bb06e29b2..fc30d532d986629d6eaf6e50a4664d28f243ac28 100644 (file)
@@ -4076,3 +4076,41 @@ gdk_surface_handle_event (GdkEvent *event)
 
   return handled;
 }
+
+gboolean
+gdk_surface_translate_coordinates (GdkSurface *from,
+                                   GdkSurface *to,
+                                   double     *x,
+                                   double     *y)
+{
+  int x1, y1, x2, y2;
+  GdkSurface *f, *t;
+
+  x1 = 0;
+  y1 = 0;
+  f = from;
+  while (f->parent)
+    {
+      x1 += f->x;
+      y1 += f->y;
+      f = f->parent;
+    }
+
+  x2 = 0;
+  y2 = 0;
+  t = to;
+  while (t->parent)
+    {
+      x2 += t->x;
+      y2 += t->y;
+      t = t->parent;
+    }
+
+  if (f != t)
+    return FALSE;
+
+  *x += x1 - x2;
+  *y += y1 - y2;
+
+  return TRUE;
+}
index b02d40192a785ded4b68db68000befce5805431b..acca090683029915f73445d3259753879af3f8a3 100644 (file)
@@ -557,6 +557,12 @@ gint          gdk_surface_get_origin     (GdkSurface      *surface,
                                           gint            *x,
                                           gint            *y);
 GDK_AVAILABLE_IN_ALL
+gboolean gdk_surface_translate_coordinates (GdkSurface *from,
+                                            GdkSurface *to,
+                                            double     *x,
+                                            double     *y);
+
+GDK_AVAILABLE_IN_ALL
 void          gdk_surface_get_frame_extents (GdkSurface     *surface,
                                              GdkRectangle  *rect);